package com.ars.common.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.text.SimpleDateFormat;

/**
 * ClassName: JSONUtil
 * Package: com.bryan.util
 * Description:
 *
 * @Author: Bryan Long
 * @Create: 2024/8/21 - 21:02
 * @Version: v1.0
 */
public class JSONUtil {
    public static String parseJson(Object obj){
        return parseJson(obj,"yy-MM-dd HH:mm:ss");
    }

    public static String parseJson(Object obj,String dateFormat){
        ObjectMapper mapper = new ObjectMapper();

        mapper.setDateFormat(new SimpleDateFormat(dateFormat));

        try {
            return mapper.writeValueAsString(obj);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
